﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Levels
{
    /// <summary>
    /// Portal moves player to the next cell
    /// </summary>
    public class Portal
    {
        #region properties
        public string ID;
        public int X;
        public int Y;
        public string NextCell;
        public Rectangle PortalRectangle;

        public bool IsEnd;
        public int[] AvatarPosInNextMapCell;
        #endregion

        #region helpers
        public string XString;
        public string YString;
        public bool RectPreapared;

        #region TEXTURE

        private bool _TextureSet;
        private Texture2D _TextureEndOfMapPortal;
        private Texture2D _TextureRegular;

        #endregion

        #endregion

        #region methods

        /// <summary>
        /// default constructor
        /// </summary>
        public Portal()
        {
            RectPreapared = false;
            IsEnd = false;

        }

        /// <summary>
        /// creates rectangle used for drawing
        /// </summary>
        public void CreateRectangle()
        {
            try
            {
                if (Util.Cache.Avatar != null)
                {
                    PortalRectangle = new Rectangle(X, Y, World.WorldManager.WorldConfig.PortalWidth, World.WorldManager.WorldConfig.PortalHeight);
                    RectPreapared = true;
                }
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// draw the portal
        /// </summary>
        public void Draw()
        {
            try
            {
                if (!_TextureSet)
                {
                    _TextureEndOfMapPortal = Util.Cache.GetTexture("HUDNextPartEndOfMap").Text2D;
                    _TextureRegular = Util.Cache.GetTexture("HUDNextPart").Text2D;
                    _TextureSet = true;

                }

                if (this.IsEnd)
                {
                    Util.Cache.Draw(_TextureEndOfMapPortal, this.PortalRectangle, Color.White);
                }
                else
                {
                    Util.Cache.Draw(_TextureRegular, this.PortalRectangle, Color.White);
                }
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        #endregion

    }
}
